Skip to content

LSPS2: Fail (or abandon) intercepted HTLCs if LSP channel open fails #3712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

martinsaposnic
Copy link

Closes #3479

Allows the LSP to signal when a channel open fails or is abandoned.

  • Fail variant: All pending payments are failed backward, and the channel state resets to PendingInitialPayment, allowing the payer to retry.
  • Abandon variant: Instead of resetting for retrial, this prunes all channel-related state, fully discarding the attempt.

Inspired by previous work and a suggestion from @tnull to add an abandon variant apart from the reset.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Apr 7, 2025

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

Copy link

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 17 lines in your changes missing coverage. Please review.

Project coverage is 89.15%. Comparing base (c6921fa) to head (5539995).

Files with missing lines Patch % Lines
lightning-liquidity/src/lsps2/service.rs 80.00% 12 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3712      +/-   ##
==========================================
- Coverage   89.15%   89.15%   -0.01%     
==========================================
  Files         156      156              
  Lines      123837   123922      +85     
  Branches   123837   123922      +85     
==========================================
+ Hits       110408   110483      +75     
+ Misses      10754    10748       -6     
- Partials     2675     2691      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 3rd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this, and excuse the delay! We'll probably wait with this until after #3509 landed either way though.

/// without resetting the state for a potential payment retry. It removes the intercept SCID
/// mapping along with any outbound channel state and related channel ID mappings associated with
/// the specified `user_channel_id`.
pub fn channel_open_abandoned(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think to make this a bit safer, it should probably fail if we're already at PendingPaymentForward or later, i.e., we already opened the channel?

Also, what would happen if this is called after the LSPS2ServiceEvent::OpenChannel has been emitted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now when abandon() is called, if it's not at PendingInitialPayment or PendingChannelOpen, then it fails.

Also, what would happen if this is called after the LSPS2ServiceEvent::OpenChannel has been emitted?

You mean if the channel is already opened, but our state machine hasn’t caught up yet and still thinks we're at PendingChannelOpen? (Is that possible?). In that case, if we call abandon(), we’d end up forgetting about a channel that was actually opened, potentially leaving funds locked. If that scenario is possible and we can't reliably detect it, then this version of abandon() isn't safe.

})?;

let jit_channel = peer_state
.outbound_channels_by_intercept_scid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation seems off.

),
})?;

jit_channel.state = match &jit_channel.state {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use the matches! macro here?

@@ -24,6 +25,7 @@ use lightning_invoice::{Bolt11Invoice, InvoiceBuilder, RoutingFees};
use bitcoin::hashes::{sha256, Hash};
use bitcoin::secp256k1::{PublicKey, Secp256k1};
use bitcoin::Network;
use lightning_types::payment::PaymentHash;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move import up.

@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

Add two LSPS2Service methods:
'Abandoned' prunes all channel open state.
'Failed' resets JIT channel to fail HTLCs.
It allows a retry on channel open.
Closes lightningdevkit#3479.
…nt forwarding

- Added a state check in channel_open_abandoned to ensure a channel cannot be abandoned after creation or payment forwarding, returning an error if attempted.
- Refactored state handling to use matches! macro for clarity.
- Addressed minor nits: fixed indentation and import ordering.
Add integration tests to verify channel open reset and
pruning handlers. Tests cover:
- channel_open_failed resetting state to allow retry.
- channel_open_failed error on invalid state.
- channel_open_abandoned pruning all open state.
- error handling for nonexistent channels.
@martinsaposnic martinsaposnic force-pushed the handle-channel-open-failure branch from 0d8ba10 to 5539995 Compare April 20, 2025 21:13
@martinsaposnic martinsaposnic requested a review from tnull April 20, 2025 21:21
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LSPS2: Fail intercepted htlcs if lsp open channel fails for whatever reason
3 participants